package com.rtp.transformer.fin.server;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.FetchMode;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.rtp.transformer.fin.client.FinService;
import com.rtp.transformer.fin.client.model.AccountCategory;
import com.rtp.transformer.fin.client.model.GLItem;
import com.rtp.transformer.fin.server.dao.FinDAO;
import com.rtp.transformer.fin.server.util.HibernateUtil;

public class FinServiceImpl extends RemoteServiceServlet implements FinService {

	 
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	protected void onAfterResponseSerialized(String serializedResponse) {
		// TODO Auto-generated method stub
		System.out.println(serializedResponse);
	}

	public List<AccountCategory> findGLByMonth(String month,  int startIndex,int pageSize) {
		 
		return FinDAO.getInstance().getAccountCategoryList(startIndex,pageSize);
	}

	public Integer getGLCount() {
		Criteria c = HibernateUtil.currentSession().createCriteria(AccountCategory.class);
		Integer count = c.setProjection(
				Projections.projectionList()
				.add(Projections.groupProperty("accountCategoryId")))
				.list().size();
		return count;
	}

	public List<GLItem> getGLItemById(Integer acId) {
		Criteria c = HibernateUtil.currentSession().createCriteria(GLItem.class);
		c.add(Restrictions.eq("parent", new AccountCategory(acId)));
		List<GLItem> result = c.list();
		return result;
	}
 
 

	 
}
